
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;

namespace Swaf
{
	/// <summary>
	/// Used to signal to clients that a message was recieved that should be processed.
	/// </summary>
	/// <param name="msgType">The type of message received, which is purely driven by the
	/// client using this class.</param>
	/// <param name="msgData">That data of the message</param>
	public delegate void processMessage(string msgType, object msgData);

	/// <summary>
	/// Used to allow multiple objects on different machines (or even the same machine)
	/// to broadcast messages to every other object in the same "conversation".</summary>
	/// <remarks>
	/// The concept of what a "conversation" is and what distiguished one from another
	/// is left completely to the implementation of this interface.  This interface
	/// simply defines the ability to send messages of various types and to
	/// add observers to messages recieved.</remarks>
	public interface IServerStateManager
	{
		/// <summary>
		/// Registers a "global" observer that will be called for every type of
		/// message recieved regarless of what the "message type" is.
		/// </summary>
		/// <param name="handler">The observer to call when a message is received.</param>
		void registerMessageHandler(processMessage handler);
		/// <summary>
		/// Registers an observer that will be called only when a particular type of
		/// message is recieved.
		/// </summary>
		/// <param name="msgType">The message type to add the observer for</param>
		/// <param name="handler">The obser to call when the message of the given type
		/// is received.</param>
		void registerMessageHandler(string msgType, processMessage handler);
		/// <summary>
		/// Removes an observer from the specific message type.
		/// </summary>
		/// <param name="msgType">The message type to remove the observer from.  Can
		/// be null to remove the "global" observer.</param>
		void unregisterMessageHandler(string msgType);
		/// <summary>
		/// Stops the instances that implements this interface from being in the
		/// "conversation" and releases any threads or other resources involved with
		/// being in the "conversation".
		/// </summary>
		void stop();

		/// <summary>
		/// Sends a string message of the given type to every object involved
		/// with the conversation.</summary>
		void sendMessage(string msgType, string message);
		/// <summary>
		/// Sends a byte array message of the given type to every object involved
		/// with the conversation.</summary>
		void sendMessage(string msgType, byte[] message);
		/// <summary>
		/// Sends an object that will be binary serialized as a message of the given
		/// type to every object involved with the conversation.</summary>
		void sendMessage(string msgType, object anObject);
	}
}
